<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网上商城</title>
    <link rel="stylesheet" th:href="@{~/bootstrap/css/bootstrap.min.css}">
    <script th:src="@{~/js/jquery-3.2.1.min.js}"></script>
    <style>
        .content{
            margin: auto;
            width: 800px;
        }
        .img{
            display: block;
            width: 150px;
            height: 180px;
        }
    </style>
</head>
<body>
    <div class="container">
        <nav class="navbar navbar-inverse">
            <ul class="nav navbar-nav">
                <li class=""><a th:href="@{/preindex/preindex}">首页 <span class="sr-only">(current)</span></a></li>

                <li><a th:href="@{/order/order}">订单</a></li>
            </ul>
        </nav>
        <div class="content">
            <div class="row">
                <div class="col-md-3">
                    <div>

                        <img class="img-rounded" th:src="@{~/img/{img}(img=${goods.img})}" alt="">
                        <span th:text="${goods.content}">

                        </span>
                    </div>
                    <div>
                        <p>
                            <i>价格：</i>
                            <b th:text="${goods.price}">3.5</b>
                            <a th:href="@{/preindex/buyOrder/{goodsid}(goodsid=${goods.id})}" id="b" class="btn btn-danger">购买</a>
                            <br/><span class="add"><b>+</b></span>
                            <span class="count">1</span>
                            <span class="desc"><b>-</b></span>
                        </p>

                    </div>

                </div>
            </div>
        </div>
        <!--<h3></h3>-->
        <div class="panel panel-primary">
            <div class="panel-heading">评论</div>
            <div class="panel-body">
                <form action="/precom/addComtent" method="post">
                    <input hidden th:value="${goods.id}" name="goodsid" />
                    <textarea name="content" style="width: 300px;height: 100px;">

                    </textarea>
                    <input type="submit" value="提交"/>
                </form>
            </div>

            <div>
                <div th:each="comtent : ${comtentsList}">
                    <span>
                        <img class="img-circle" width="30" height="30" th:src="@{~/img/{img}(img=${comtent.user.img})}" alt="">
                        <span th:text="${comtent.user.uname}"></span>
                    </span>
                    <span th:text="${comtent.content}">

                    </span>
                </div>
            </div>


        </div>
        
    </div>
</body>
<script>
    $(function(){
        var href=$(".btn-danger").attr("href");
        var count = 0;
        $(".add").click(function(){
            console.log("执行了+")
            count = parseInt($(".count").text());
            $(".count").text(count+1);
        })
        $(".desc").click(function(){
            count = parseInt($(".count").text());
            if(count>1){
                $(".count").text(parseInt(count-1));
            }
        })
        $("#b").click(function(){
            if(count!=0){
                href = href+"?count="+parseInt($(".count").text());
                $(".btn-danger").attr("href",href);
            }
        })



    })
</script>
</html>